﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Permissions.Models;
using Permissions.RoleApp.Dto;

namespace Permissions.RoleApp
{
    public class RoleAppService : IRoleAppService
    {
        private readonly IRepository<Role> _roleRepository;

        public RoleAppService(IRepository<Role> roleRepository)
        {
            _roleRepository = roleRepository;
        }

        public void CreateRole(CreateRoleInput input)
        {
            var role = new Role { Name = input.Name };

            _roleRepository.Insert(role);
        }

        public ListResultDto<RoleDto> GetRoles()
        {
            var roles = _roleRepository.GetAll();

            return new ListResultDto<RoleDto>(roles.MapTo<List<RoleDto>>());
        }

        public void UpdateRole(UpdateRoleInput input)
        {
            var role = _roleRepository.Get(input.Id);

            _roleRepository.Update(input.MapTo(role));
        }
    }
}
